package com.toughsoftware.pins.adapter;

import java.sql.Date;

import org.joda.time.DateTime;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.toughsoftware.pins.R;
import com.toughsoftware.pins.data.bean.BnPin;

public class AdptrPinBean extends ArrayAdapter<BnPin> {
	
	Activity context;
	//DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
	static DateTime dt2 = new DateTime(2005, 3, 23, 12, 0, 0, 0);
	static DateTime dt4 = new DateTime(2013, 3, 7, 23, 5, 10, 12);
	
	private static BnPin[] datos = 
	    	new BnPin[]{
	    		new BnPin("Pin Title 1",true, new Date(System.currentTimeMillis()), "Foto Pin 1", "Texto Pin 1"),
	    		new BnPin("Pin Title 2",true, new Date(dt2.getMillis()), "Foto Pin 2", "Texto Pin 2"),
	    		new BnPin("Pin Title 3",false, new Date(System.currentTimeMillis()), "Foto Pin 3", "Texto Pin 3"),
	    		new BnPin("Pin Title 4",true, new Date(dt4.getMillis()), "Foto Pin 4", "Texto Pin 4"),
	    		new BnPin("Pin Title 5",false, new Date(System.currentTimeMillis()), "Foto Pin 5", "Texto Pin 5")};
	
	public AdptrPinBean(Fragment context) {
		super(context.getActivity(), R.layout.pin_bean, datos);
		this.context = context.getActivity();
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = context.getLayoutInflater();
		View item = inflater.inflate(R.layout.pin_bean, null);
				
		TextView tvPinTitle = (TextView)item.findViewById(R.id.tvPinTitle);
		tvPinTitle.setText(datos[position].getStrPinTitle());
		
		ToggleButton tbPinIsFav = (ToggleButton)item.findViewById(R.id.tbPinIsFav);
		tbPinIsFav.setChecked(datos[position].isFavorite());
		
		TextView tvPinWhen = (TextView)item.findViewById(R.id.tvPinWhen);
		tvPinWhen.setText(datos[position].getDtPinWhen().toString());
		
		TextView tvPinComment = (TextView)item.findViewById(R.id.tvPinComment);
		tvPinComment.setText(datos[position].getStrPinComment().toString());
		
		TextView tvPinMultimedia = (TextView)item.findViewById(R.id.tvPinMultimedia);
		tvPinMultimedia.setText(datos[position].getMultimedia().toString());
		
		return(item);
	}
}
